﻿using HrEFCore;
using HrIService;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HrService
{
    public class CMKService : ICMKService
    {
        private readonly MyDbContext myDbContext;
        public CMKService(MyDbContext myDbConext)
        {
            this.myDbContext = myDbConext;
        }

        public async Task<int> Add(CMK cMK)
        {
            //添加CMK表数据
            myDbContext.CMK.Add(cMK);
            return await myDbContext.SaveChangesAsync();
        }

        public async Task<int> DeleteMfkId(short mfkId)
        {
            //根据ID删除
            var cMK = await myDbContext.CMK.FindAsync(mfkId);
            if (cMK != null)
            {
                myDbContext.CMK.Remove(cMK);
                return await myDbContext.SaveChangesAsync();
            }
            return 0;
        }

        public Task<List<CMK>> InquireAll()
        {
            //查询CMK所有数据
            return myDbContext.CMK.ToListAsync();
        }

        public async Task<int> InquireMajorKindId()
        {
            //查询职位分类编号
            short maxMajorKindId = await myDbContext.CMK.MaxAsync(c => c.MfkId);
            return maxMajorKindId;
        }

		public async Task<CMK> SelectById(string id)
		{
            return await myDbContext.CMK.FirstOrDefaultAsync(e=>e.MajorKindId==id);
		}
	}
}
